#include <fstream>
#include <sstream>
#include <vector>
#include "utils.hpp"

Mat read_csv(const string &filename) {
    fstream fin;
    fin.open(filename, ios::in);
    vector<double> values;
    string line;
    int row=0, column=0;
    while (getline(fin, line)) {
        istringstream sin(line);
        string value;
        column = 0;
        while (getline(sin, value, ',')) {
            values.push_back(stod(value));
            column++;
        }
        row++;
    }
    return Mat(row, column, values);
}

void Print_Vector(vector<uint32_t> data) {
    for (int i = 0; i < data.size(); i++)
        cout << data[i] << ", ";
    cout << endl;
}

bool Find_vector(vector<uint32_t>& data, uint32_t x) {
    for (int i = 0; i < data.size(); i++)
        if (data[i] == x)
            return true;
    return false;
}

int CountOnesFromInteger(uint32_t i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
int CountSetBits(uint32_t n) {
    uint32_t count = 0;
    while (n) {
        n &= (n-1);
        count++;
    }
    return count;
}
